package edu.sctu.practice.class01.zhangwang.day2015_10_08.text03;

/**
 * Created by Z_W on 2015/10/8.
 */
public class MyTime {
    private int hour;
    private int minute;
    private int second;

    public MyTime(int hour, int minute, int second) {
        this.hour = hour;
        this.minute = minute;
        this.second = second;
    }

    public void display() {
        System.out.println(hour + "时" + minute + "分" + second + "秒");
    }

    public void addSecond(int second) {
        this.second += second;
        if (this.second >= 60) {
            minute += 1;
            this.second = this.second - 60;
        }
        addMinute(0);
    }

    public void addMinute(int minute) {
        this.minute += minute;
        if (this.minute >= 60) {
            hour += 1;
            this.minute = this.minute - 60;
        }
    }

    public void addHour(int hour) {
        this.hour += hour;
    }

    public void subSecond(int second) {
        this.second -= second;
        if (this.second <= 0) {
            minute -= 1;
            this.second = 60 + this.second;
        }
        subMinute(0);
    }

    public void subMinute(int minute) {
        this.minute -= minute;
        if (this.minute <= 0) {
            hour -= 1;
            this.minute = 60 + this.minute;
        }
        subHour(0);
    }

    public void subHour(int hour) {
        this.hour -= hour;
        if (this.hour <= 0) {
            System.out.println("时间不能为负数！");
        }
    }
}
